package com.example.smartwaterapi.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.smartwaterapi.entity.UserWatchface;
import com.example.smartwaterapi.mapper.UserWatchfaceMapper;
import com.example.smartwaterapi.service.UserWatchfaceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.io.Serializable;

/**
 * 用户表盘服务实现类
 */
@Slf4j
@Service
public class UserWatchfaceServiceImpl extends ServiceImpl<UserWatchfaceMapper, UserWatchface> implements UserWatchfaceService {

    @Override
    public boolean save(UserWatchface entity) {
        log.info("保存用户表盘数据: {}", entity);
        try {
            boolean result = super.save(entity);
            if (result) {
                log.info("用户表盘数据保存成功, id: {}", entity.getId());
            } else {
                log.error("用户表盘数据保存失败");
            }
            return result;
        } catch (Exception e) {
            log.error("保存用户表盘数据异常", e);
            throw e;
        }
    }
    
    @Override
    public boolean updateById(UserWatchface entity) {
        log.info("更新用户表盘数据, id: {}", entity.getId());
        try {
            boolean result = super.updateById(entity);
            if (result) {
                log.info("用户表盘数据更新成功, id: {}", entity.getId());
            } else {
                log.warn("用户表盘数据更新失败, id: {}, 可能记录不存在", entity.getId());
            }
            return result;
        } catch (Exception e) {
            log.error("更新用户表盘数据异常, id: {}", entity.getId(), e);
            throw e;
        }
    }
    
    @Override
    public UserWatchface getById(Serializable id) {
        log.info("获取用户表盘数据, id: {}", id);
        try {
            UserWatchface watchface = super.getById(id);
            if (watchface == null) {
                log.warn("未找到用户表盘数据, id: {}", id);
            }
            return watchface;
        } catch (Exception e) {
            log.error("获取用户表盘数据异常, id: {}", id, e);
            throw e;
        }
    }
    
    @Override
    public boolean removeById(Serializable id) {
        log.info("删除用户表盘数据, id: {}", id);
        try {
            boolean result = super.removeById(id);
            if (result) {
                log.info("用户表盘数据删除成功, id: {}", id);
            } else {
                log.warn("用户表盘数据删除失败, id: {}, 可能记录不存在", id);
            }
            return result;
        } catch (Exception e) {
            log.error("删除用户表盘数据异常, id: {}", id, e);
            throw e;
        }
    }
} 